<?php

declare(strict_types=1);

namespace app\admin\controller\user;


use think\response\Json;
use app\admin\controller\Controller;

class User extends Controller
{
    protected $service = null;
    protected array $middleware = [
        'admin'     => ['except'     => ['lists']],
    ];
    public function initialize()
    {
        parent::initialize();
        $this->service = new \app\admin\service\user\UserService();
    }

    /**
     * 列表
     * @return Json
     * @throws \think\db\exception\DbException
     */
    public function list(): Json
    {
        return success($this->service->list());
    }

    public function lists(): Json
    {
        return success($this->service->lists());
    }

    public function detail(int $id): Json
    {
        return success($this->service->detail($id));
    }
    
    public function create(): Json
    {
        return success('创建成功', $this->service->create(request()->param()));
    }

    public function update(): Json
    {
        $id = request()->param('id');
        return success('更新成功', $this->service->update($id, request()->param()));
    }

    public function delete(): Json
    {
        $id = request()->param('id');
        return $this->service->delete($id);
    }

    public function cart(): Json
    {
        return success($this->service->cart());
    }

    public function del_cart(): Json
    {
        $id = request()->param('id');
        return $this->service->del_cart($id);
    }

    public function privacy(): Json
    {
        return success($this->service->privacy());
    }

    public function examine(): Json
    {
        $id = request()->param('id');
        return success('处理成功', $this->service->examine($id, request()->param()));
    }

    public function select(): Json
    {
        return success($this->service->select());
    }
}
